package com.bawei.composeui2207a.day02

import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.bawei.composeui2207a.R

/**
 * 作者：赵亮
 * 时间：2024/12/11 12:05
 * 功能：对话框
 */
@Composable
fun Page10() {
    // 对话框状态
    var isShow by remember {
        mutableStateOf(false)
    }

    Column {
        Button(onClick = {
            // 显示对话框，修改状态变量
            isShow = true
        }) {
            Text(text = "显示对话框")
        }

        if (isShow) {
            AlertDialog(
                onDismissRequest = { isShow = false },
                confirmButton = {
                    Text(text = "确定", modifier = Modifier.clickable {
                        Log.i("TAG", "Page10: 点击确定")
                        isShow = false
                    })
                    /* Button(onClick = { *//*TODO*//* }) {
                        Text(text = "确定")
                    }*/
                    // Icon(imageVector = Icons.Default.Search, contentDescription = null)
                },
                dismissButton = {
                    Text(text = "取消", modifier = Modifier.clickable {
                        Log.i("TAG", "Page10: 点击取消")
                        isShow = false
                    })
                },
                /*icon = {
                    Icon(imageVector = Icons.Default.LocationOn, contentDescription = null)
                },*/
                title = {
                    Text(text = "提示！")
                },
                text = {
                    //Text(text = "危险操作！")
                    Image(
                        painter = painterResource(id = R.drawable.sunwukong),
                        contentDescription = null
                    )
                }
            )
        }
    }

}

@Preview(showSystemUi = true)
@Composable
fun Page10Preview() {
    Page10()
}

